*************************************************************************************
*************************************************************************************
** Replication code for:
** US Public Perceptions of an Intelligence Quotient Test Score Gap Between Black Americans and White Americans 
** GSS 2016 
** dataset downloaded 7 Jan 2019
** http://gss.norc.org/get-the-data/stata
** Stata 15
*************************************************************************************
*************************************************************************************

set more off
svyset vpsu [pw=wtssall], strata(vstrat) singleunit(centered)

*******************************************************************************************************************************
*** Stereotype: intelligent
*******************************************************************************************************************************

tab1 intlwhts intlblks
tab1 intlwhts intlblks, mi
tab1 intlwhts intlblks, mi nol
tab  intlwhts intlblks
tab  intlwhts intlblks, mi
tab  intlwhts intlblks, mi nol

gen intelWB = 0
replace intelWB = 1 if intlwhts>intlblks
replace intelWB = . if intlwhts==.i | intlblks==.i
replace intelWB = 0 if intlwhts==.d | intlwhts==.n | intlblks==.d | intlblks==.n
tab intelWB, mi
tab intlwhts intelWB, mi
tab intlblks intelWB, mi

tab intlwhts intlblks if intelWB==1, mi
tab intlwhts intlblks if intelWB==0, mi
tab intlwhts intlblks if intelWB==., mi
sum intelWB

*******************************************************************************************************************************
*** Racial groups
*******************************************************************************************************************************

tab hispanic race, mi
gen whiteNH = 0
gen blackNH = 0
replace whiteNH=1 if race==1 & hispanic==1
replace blackNH=1 if race==2 & hispanic==1
tab race hispanic if whiteNH==1, mi
tab race hispanic if blackNH==1, mi
tab race whiteNH
tab race blackNH

* Compare to NH White moderate % in YouGov data
tab polviews, mi
tab polviews, nol mi
gen pol8 = polviews
replace pol8=8 if polviews==.d | polviews==.n // recode so that 8 is don't know or no answer
tab pol8 polviews, mi
svy: tab pol8 if whiteNH==1
di 0.0459 + 0.1188 + 0.1054 // liberal
di 0.1523 + 0.1785 + 0.0390 // conservative
di 0.3349                   // moderate
di 0.0252                   // don't know or no answer

tab polviews
tab polviews, nol mi
gen liberal=0
gen conserv=0
replace liberal=1 if polviews==1 | polviews==2 | polviews==3
replace conserv=1 if polviews==5 | polviews==6 | polviews==7
tab polviews liberal, mi
tab polviews conserv, mi

gen whiteNHlib = 0
gen whiteNHcon = 0
replace whiteNHlib=1 if whiteNH==1 & liberal==1
replace whiteNHcon=1 if whiteNH==1 & conserv==1
tab polviews whiteNHlib, mi
tab polviews whiteNHcon, mi
tab race whiteNHlib, mi
tab race whiteNHcon, mi
tab hispanic whiteNHlib, mi
tab hispanic whiteNHcon, mi

*******************************************************************************************************************************
*** Analyses
*******************************************************************************************************************************

svyset vpsu [pw=wtssall], strata(vstrat) singleunit(centered)
svy:                     prop intelWB, level(84)
svy, subpop(whiteNH):    prop intelWB, level(84)
svy, subpop(blackNH):    prop intelWB, level(84)
svy, subpop(whiteNHlib): prop intelWB, level(84)
svy, subpop(whiteNHcon): prop intelWB, level(84)

svy:                     prop intelWB, level(95)
svy, subpop(whiteNH):    prop intelWB, level(95)
svy, subpop(blackNH):    prop intelWB, level(95)
svy, subpop(whiteNHlib): prop intelWB, level(95)
svy, subpop(whiteNHcon): prop intelWB, level(95)
